<template>
	<view>
		<scroll-view scroll-x="true" class="arts">
			<view class="tip">
				<view class="tipItem" :class="tipIndex == index ? 'tipActive':''" v-for="(item,index) in tipList" :key="index" @tap="tipClick(item.im_type_id,index)">{{item.im_type_name}}</view>
			</view>
		</scroll-view>
		<list :list='news' :status="status" :contentText="contentText" stateType="2" addType="2"></list>
	</view>
</template>

<script>
	import util from '@/common/util.js';
	import list from '@/components/artlist/artlist';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default{
		components: {
			list,
			uniLoadMore
		},
		data() {
			return {
				page: 1,
				reload: true,
				status: 'more',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多',
					contentnot: "没数据"
				},
				news: [], //文章列表
				tipList: [], //标签列表
				tipIndex: 0, //标签索引
			}
		},
		onPullDownRefresh() {
			this.reload = true;
			this.page = 1;
			this.getArt();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.status = 'loading';
			this.page = this.page + 1;
			var _this = this;
			setTimeout(function() {
				_this.getArt();
			}, 500);
		},
		onShow() {
			this.reload = true;
			this.page = 1;
			this.getTip();
		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url: '/pages/articleModule/article-childMe'
			})
		},
		methods: {
			/* 获取文章列表 */
			getArt() {
				var data = {
					page: this.page,
					pagesize: 7,
					im_type_id: this.tipList[this.tipIndex].im_type_id
				}
				this.$zapi.apiPost('user/information.Lists/InformationList', data).then(res => {
					if (res.data.code == 200 && res.data.data.data) {
						var list = res.data.data.data;
						for (var i = 0; i < list.length; i++) {
							list[i].time = util.getBriefTime(list[i].creat_time);
						}
						this.news = this.reload ? list : this.news.concat(list);
						this.reload = false;
						this.status = 'more';
					} else {
						if (this.reload) {
							this.list = [];
						} else {
							this.status = 'noMore';
						}
					}
				})
			},
			/* 获取标签列表 */
			getTip(){
				this.$zapi.apiPost('user/information.Lists/listType').then(res => {
					if (res.data.code == 200 && res.data.data) {
						this.tipList = res.data.data;
						this.tipList.unshift({
							im_type_name: "全部",
							im_type_id: 0
						});
						this.getArt();
					} else {
						this.tipList = [];
						this.tipList.unshift({
							im_type_name: "全部",
							im_type_id: 0
						});
						this.getArt();
					}
				})
			},
			/* nav切换 */
			navClick(index) {
				this.navIndex = index;
				this.reload = true;
				this.page = 1;
				this.tipIndex = 0;
				if(this.navIndex == 1) {
					this.getArt();
				}
			},
			/* 暂未开通 */
			none() {
				uni.showToast({
					title: '该功能暂未开通',
					icon: 'none'
				})
			},
			/* tip切换 */
			tipClick(id,index) {
				this.tipIndex = index;
				this.reload = true;
				this.page = 1;
				this.getArt();
			}
		},
	}
</script>

<style>
	/* 内容 */
	.arts{
		position: fixed;
		top: 0upx;
		left: 0;
		background: #FAFAFA;
		z-index: 2;
	}
	.tip{
		display: flex;
		justify-content: flex-start;
		align-items: center;
		border-top: 30upx solid #FAFAFA;
		border-bottom: 30upx solid #FAFAFA;
		white-space: nowrap;
	}
	.tipItem{
		color: #999999;
		font-size: 30upx;
		padding: 8upx 22upx;
		border: 2upx solid #CCCCCC;
		line-height: 1;
		text-align: center;
		border-radius: 26upx;
		margin-left: 30upx;
		margin-right: 10upx;
	}
	.tipActive{
		color: #FFFFFF;
		background: #FF9900;
		border: 2upx solid #FF9900;
	}
</style>